package org.jugile.util;

/*

Copyright (C) 2007-2011 Jukka Rahkonen  email: jukka.rahkonen@iki.fi

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/

import java.io.Serializable;


/**
 * "And I will set the Egyptians against the Egyptians: and they shall fight 
 *  every one against his brother, and every one against his neighbour; 
 *  city against city, and kingdom against kingdom." (Isaiah 19:2)
 * 
 * ==========
 * 
 * Domain Object Handle. 
 * Identifies object, its type and home (if in distributed env). 
 * This enables objects to know their home and to determine which version is 
 * the original and which is copy (or proxy). Base for net objects.
 * 
 * @author jukka.rahkonen@iki.fi
 */
public class DOH extends Jugile implements Serializable {
	private String id;
	private String domainClassName;
	private String home; // usually ip address
	
	public DOH(String domainClassName, String id) {
		this.domainClassName = domainClassName;
		this.id = id;
	}
	
	public DOH(String doh) {
		if (empty(doh)) return;
		String p[] = doh.split(":");
		if (p.length != 3) fail("invalid Domain Object Handle");
		home = p[0];
		domainClassName = p[1];
		id = p[2];
	}
	
	public String toString() {
		return nn(home) + ":" + nn(domainClassName) + ":" + nn(id);
	}
	
	public int hashCode() { return toString().hashCode(); }
	public boolean equals(Object o) {
		if (o == null) return false;
		if (o instanceof DOH) return toString().equals(o.toString());
		return false;
	}	
	
	public String getId() { return id; }
	public String getDomainClassName() { return domainClassName; }
	public String getHome() { return home; }
	
}
